package com.ios.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ios.model.entity.Seat;
import com.ios.service.SeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/seat")
public class SeatController extends BaseController {
    @Autowired
    private SeatService seatService;

    /**
     * 查询座位列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Seat seat) {
        startPage();
        List<Seat> list = seatService.selectSeatList(seat);
        return getDataTable(list);
    }

    /**
     * 获取座位详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(seatService.selectSeatById(id));
    }

    /**
     * 新增座位
     */
    @PostMapping
    public AjaxResult add(@RequestBody Seat seat) {
        try {
            return toAjax(seatService.insertSeat(seat));
        } catch (RuntimeException e) {
            return error(e.getMessage()); // 返回校验错误信息
        }
    }
    /**
     * 修改座位
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Seat seat) {
        try {
            return toAjax(seatService.updateSeat(seat));
        } catch (RuntimeException e) {
            return error(e.getMessage());
        }
    }
    /**
     * 删除座位
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(seatService.deleteSeatByIds(ids));
    }
}